package org.ourgrid.worker.collectors.common;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ourgrid.common.interfaces.WorkerSpecListener;
import org.ourgrid.worker.collectors.interfaces.WorkerCollectorClient;

import br.edu.ufcg.lsd.commune.api.Remote;
import br.edu.ufcg.lsd.commune.identification.ServiceID;

@Remote
public class WorkerSpecCreator implements WorkerCollectorClient {
	
	private static final long serialVersionUID = 1L;
	
	private WorkerSpecListener peerOwner;
	private WorkerSpecListener peerDonated;
	private WorkerSpecListener broker;
	
	public WorkerSpecCreator() {}
	
	public void metricsChanged(ServiceID entityId, Collection<Metric> metrics) {
		Map<String,String> attr = new HashMap<String,String>();
		for (Metric metric : metrics) {
			attr.put(metric.getName(), metric.getValue());
		}

		//TODO
//		WorkerSpec spec = new WorkerSpec(attr);
//		if(peerOwner != null)
//			peerOwner.updateWorkerSpec(spec);
//		if(peerDonated != null)
//			peerDonated.updateWorkerSpec(spec);
//		if(broker != null)
//			broker.updateWorkerSpec(spec);
	}
	
	public WorkerSpecListener getBroker() {
		return broker;
	}
	
	public void setBroker(WorkerSpecListener broker) {
		this.broker = broker;
	}
	
	public WorkerSpecListener getPeerDonated() {
		return peerDonated;
	}
	
	public void setPeerDonated(WorkerSpecListener peerDonated) {
		this.peerDonated = peerDonated;
	}
	
	public WorkerSpecListener getPeerOwner() {
		return peerOwner;
	}
	
	public void setPeerOwner(WorkerSpecListener peerOwner) {
		this.peerOwner = peerOwner;
	}

	public void metricsChanged(ServiceID serviceID, List<Metric> metrics) {
		// TODO Auto-generated method stub
		
	}

}
